/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 ******************************************************************************/

package org.reliablesource.pleiades;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @since 3.2
 * 
 */
public class ReliableSimpleComment extends ReliableResource {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected String authorId;

	protected List<ReliableRating> ratingsList;
	protected List<ReliableSimpleComment> replies;
	protected ReliableResource resource;
	protected String commentText;

	public ReliableSimpleComment(String _authorId) {
		super();
		authorId = _authorId;
		replies = new LinkedList<ReliableSimpleComment>();
		ratingsList = new LinkedList<ReliableRating>();
	}

	public ReliableRating[] getRatingsList() {
		return ratingsList.toArray(new ReliableRating[ratingsList.size()]);
	}

	protected void setRatingsList(List<ReliableRating> _ratingsList) {
		ratingsList = _ratingsList;
	}

	public boolean submitRating(final ReliableRating _rating) {
		if (null != _rating)
			if (!ratingsList.contains(_rating))
				return ratingsList.add(_rating);

		return false;
	}

	public String getAuthorId() {
		return authorId;
	}

	public String getCommentText() {
		return commentText;
	}

	public void setCommentText(String _text) {
		commentText = _text;
	}

	public ReliableSimpleComment[] getReplies() {
		return replies.toArray(new ReliableSimpleComment[replies.size()]);
	}

	public List<ReliableSimpleComment> getRepliesList() {
		return new ArrayList<ReliableSimpleComment>(replies);
	}

	public boolean submitReply(final ReliableSimpleComment _reply) {
		if (null != _reply)
			if (!replies.contains(_reply))
				return replies.add(_reply);

		return false;
	}

	public ReliableResource getBinding() {
		return resource;
	}

	public void setBinding(ReliableResource _binding) {
		resource = _binding;
	}
}
